﻿using Catastrophe.Log;
using CefSharp;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Catastrophe.BasePC.UI.UIMode
{
    /// <summary>
    /// 系统日志
    /// </summary>
    public partial class UcSysLogModel : ObservableObject
    {
        /// <summary>
        /// 
        /// </summary>
        private SysLogDal _dbLog { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [ObservableProperty]
        private DateTime startTime;
        /// <summary>
        /// 
        /// </summary>
        [ObservableProperty]
        private DateTime stopTime;

        /// <summary>
        /// 数据
        /// </summary>
        [ObservableProperty]
        private ObservableCollection<SysLogEntity> listData;

        /// <summary>
        /// 
        /// </summary>
        public ICommand SelectData {  get; set; }
        public UcSysLogModel()
        {
            _dbLog = new SysLogDal
            {
                SoftId = LogSession.SoftId
            };
            var stime = DateTime.Now;
            stime = stime.AddDays(-30);
            StartTime = stime;
            StopTime = DateTime.Now.AddDays(1);
            listData = new ObservableCollection<SysLogEntity>();
            SelectData = new RelayCommand(DtRefresh);
            DtRefresh();
        }
        /// <summary>
        /// 刷新
        /// </summary>
        private void DtRefresh()
        {
            listData.Clear();
            var data = _dbLog.QueryLogToList(StartTime, StopTime);
            data.ForEach(x => listData.Add(x));
        }
    }
}
